<?php

class My_Plugin_Cache extends Zend_Controller_Plugin_Abstract {

    /**
     * Called before Zend_Controller_Front calls on the router
     * to evaluate the request against the registered routes.
     * @param Zend_Controller_Request_Abstract $request
     */
    public function routeStartup(Zend_Controller_Request_Abstract $request) {
        $appConfig = My_Global::getApplicationIni();
        
        $frontend = array(
            'lifetime' => 7200,
            'debug_header' => $appConfig->pagecache->debug, // for debugging
            'regexps' => array(
                '^/' => array(
                    'cache' => false,
                ),
                // cache the whole InformationController
                '^/thong-tin/' => array(
                    'cache' => true,
                ),
                '^/thong-tin/lien-he.html' => array(
                    'cache' => false,
                )
            )
        );

        
        
        $backend = array(
            'servers' => array(
                array('host' => $appConfig->pagecache->host, 'port' => $appConfig->pagecache->port)
            ),
            'compression' => false
        );
        $cache = Zend_Cache::factory('Page', 'Memcached', $frontend, $backend);
        $cacheID = md5($request->getRequestUri());
        $cache->start($cacheID);
    }

    /**
     * Called after the router finishes routing the request.
     * @param Zend_Controller_Request_Abstract $request
     */
    public function routeShutdown(Zend_Controller_Request_Abstract $request) {
        
    }

    /**
     * Called before Zend_Controller_Front enters its dispatch loop.
     * @param Zend_Controller_Request_Abstract $request
     */
    public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) {
        
    }

    /**
     * Called before an action is dispatched by the dispatcher.
     * This callback allows for proxy or filter behavior.
     * By altering the request and resetting its dispatched flag
     * via Zend_Controller_Request_Abstract::setDispatched(false),
     * the current action may be skipped and/or replaced.
     * @param Zend_Controller_Request_Abstract $request
     */
    public function preDispatch(Zend_Controller_Request_Abstract $request) {
        
    }

    /**
     * Called after an action is dispatched by the dispatcher.
     * This callback allows for proxy or filter behavior.
     * By altering the request and resetting its dispatched flag
     * via Zend_Controller_Request_Abstract::setDispatched(false)),
     * a new action may be specified for dispatching.
     * @param Zend_Controller_Request_Abstract $request
     */
    public function postDispatch(Zend_Controller_Request_Abstract $request) {
        
    }

    /**
     * Called after Zend_Controller_Front exits its dispatch loop.
     */
    public function dispatchLoopShutdown() {
        
    }

}

